package com.gujia.rabbitmq.work;

import com.gujia.rabbitmq.util.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import jdk.nashorn.internal.objects.NativeUint8Array;

import java.io.IOException;

public class Sender {
    private static final String QUEUE_NAME="test_work_queue";

    public static void main(String[] args) throws Exception {
        //获取一个连接
        Connection connection = ConnectionUtils.getConnction();
        //从连接中获取一个通道
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);

        for (int i = 0; i <50 ; i++) {
            String msg = "hello"+i;
            channel.basicPublish("",QUEUE_NAME, null,msg.getBytes());
            Thread.sleep(i+20);
            System.out.println("send:"+msg);
        }

        channel.close();
        connection.close();
    }
}
